package tag.system;

import java.io.FileNotFoundException;
import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.eu.base.io.TextOperator;

public class Template extends BodyTagSupport {

	String file = null;

	public int doStartTag() throws JspException {
		String base = this.pageContext.getServletContext().getRealPath(
				"/WEB-INF/template/");
		TextOperator tr=null;
		try {
			tr = new TextOperator(base + "/" + file);
		} catch (FileNotFoundException e1) {
			return BodyTag.SKIP_BODY;
		}
		String content = tr.readAll();
		try {
			pageContext.getOut().print(content);
		} catch (IOException e) {
			e.printStackTrace();
		}
		return super.doStartTag();
	}

	public String getFile() {
		return file;
	}

	public void setFile(String file) {
		this.file = file;
	}

	private static final long serialVersionUID = 5961748813650589670L;

}
